package com.foxconn.ipebg.common.base.controller;

import ipebg.mzk.facade.system.service.MsFunctionOptionService;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.foxconn.ipebg.common.base.security.SecurityUserHolder;

@Controller
@RequestMapping("/common.do")
public class CommonController {

	@Resource(name = "msFunctionOptionServiceImpl")
	private MsFunctionOptionService msFunctionOptionServiceImpl;

	@RequestMapping(params = "action=getButtons")
	public void getButton(HttpServletRequest request, HttpServletResponse response) {
		// Object username = request.getSession().getAttribute("username");
		String strResult = null;
		String functionId = request.getParameter("functionId");
		Object username = SecurityUserHolder.getCurrentUser().getUsername();
		PrintWriter out = null;
		if (username != null) {
			strResult = JSON.toJSONString(msFunctionOptionServiceImpl.findOptionByLoginNameFunctionId(username.toString(), functionId));
		} else {
			Map result = new HashMap();
			result.put("result", "FAILED");
			strResult = JSON.toJSONString(result);
		}		
		System.out.print(strResult);
		try {
			response.getWriter().write(strResult);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
